package com.settlement.system.converter;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.settlement.system.common.enums.CostAllocationEnum;
import org.apache.commons.lang3.StringUtils;

/**
 * 是否分摊
 * @author author
 */
public class ShareOrNotConvert extends StringStringConverter {

    @Override
    public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        if(StringUtils.isNotEmpty(value)){
            String replace = value.replace(CostAllocationEnum.ShareOrNotEnum.NO.getNo(), CostAllocationEnum.ShareOrNotEnum.NO
                    .getName())
                    .replace(CostAllocationEnum.ShareOrNotEnum.YES.getNo(), CostAllocationEnum.ShareOrNotEnum.YES.getName());
            return new WriteCellData(replace);
        }
        return new WriteCellData("");
    }

    @Override
    public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String value = super.convertToJavaData(cellData, contentProperty, globalConfiguration);
        if(!StringUtils.isEmpty(value)){
            return CostAllocationEnum.ShareOrNotEnum.getNoByName(value);
        }
        return null;
    }
}
